Skip to content

[Feature] [U2x CCRH/GHS Porting] Implement Dedicated Stack for ISRs #24

@nguyentri

Description

@nguyentri

**Description: **
This issue proposes implementing a separate, dedicated stack for Interrupt Service Routines (ISRs) to improve system stability and prevent unpredictable stack overflows.

Current Behavior
Currently, when an interrupt preempts a running task, the subsequent ISR executes using the stack of the interrupted task. This means the ISR's stack frame and any nested function calls consume the stack space allocated for that specific task.

The Problem
This design creates a high risk of stack overflow and makes stack size calculation unreliable for two main reasons:

Non-Deterministic Stack Usage: The required stack size for a task becomes dependent not only on its own call tree but also on the worst-case stack usage of any ISRs that could possibly preempt it, especially nested interrupts or high frequent interrupts occurring.

High Risk of Overflow: A task that is functioning correctly with its allocated stack can crash unexpectedly if it's preempted by a complex, stack-heavy ISR. These overflows are often timing-dependent and extremely difficult to debug.

Proposed Solution
The port should be modified to switch to a dedicated interrupt stack when an ISR is triggered. The standard implementation flow for this is as follows:

  • An interrupt occurs.

  • The minimal context of the interrupted task is saved on the task's stack.

  • The CPU's stack pointer (SP) for each CPU is switched to point to a pre-allocated, dedicated interrupt stack respectively.

  • The main body of the C-level ISR handler is then executed using this safe, dedicated stack.

  • Upon completion of all ISRs, the SP is switched back to the task's stack before its full context is restored and execution resumes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions