This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

how many registers are pushed into the stack when running an ISR ?

I want to change the return address in the stack when running an ISR so that it returns to the specified address. But i found the compiler also pushes some variables to the stack. How can I configure the complier so that it only pushes all registers to the stack when it complies an ISR?

thank you for your kindly help!!

Parents
  • i want to do context switch within the timer ISR.

    Ok. This is actually one of the few cases where manually changing the return address might be necessary.

    However, think about what the term context implies. A context switch is not done by just setting the program counter to the new address. Each context also has its own registers and (usually) stack (pointer). If you are working with C, then the context can include even more variables (for example any variable used inside one of the libraries you use).

    You probably won't be able to avoid using assembly in your OS. You can write the task switcher in a mix of assembly and C (start and end with assembly, call a function in C) if it is too complex to be written in pure assembly. On the plus side, using assembly will give you complete control over which registers are pushed to the stack.

Reply
  • i want to do context switch within the timer ISR.

    Ok. This is actually one of the few cases where manually changing the return address might be necessary.

    However, think about what the term context implies. A context switch is not done by just setting the program counter to the new address. Each context also has its own registers and (usually) stack (pointer). If you are working with C, then the context can include even more variables (for example any variable used inside one of the libraries you use).

    You probably won't be able to avoid using assembly in your OS. You can write the task switcher in a mix of assembly and C (start and end with assembly, call a function in C) if it is too complex to be written in pure assembly. On the plus side, using assembly will give you complete control over which registers are pushed to the stack.

Children