-2

When CPU receives exception, Pre-processing by hardware Saving the current PC and PSW values in RAM (or in control registers in the case of the fast interrupt) and Reading of the vector Branching to the start of the exception handling routine is done.But, General purpose registers and control registers other than the PC and PSW that are to be used within the exception handling routine must be preserved on the stack by user program code at the start of the exception handling routine. Reverse is repeated by user code and hardware upon returning from exception. (Reference: Renesas Rx62n hardware manual, page 297, Chapter:Exceptions)

My question is where is this user code for context switching and how it is getting called?

Chandan Kumar
  • 17
  • 1
  • 5
  • The runtime should be, or your own freestanding code – Basile Starynkevitch Sep 22 '17 at 11:39
  • if this is bare metal then it is all your code, you wrote it, you know where this code is that does all of this. It really has nothing to do with bare metal, nor this specific chip vendor nor architecture this is how exception handling works. You have to preserve state so you can return to the interrupted code as if nothing happened but time passing. – old_timer Sep 22 '17 at 13:41
  • if this is not an OS then why are you context switching? – old_timer Sep 22 '17 at 13:41
  • Context switching is needed for exception and interrupt handling and it is not only for task switching which is done by OS. I have learnt that some of the contexts are saved and restored by hardware itself but have no idea about other contexts. – Chandan Kumar Sep 23 '17 at 06:17

1 Answers1

0

As per the Renesas CC-RX compiler document, To declare any global function as ISR we need to specify it as

#pragma interrupt func
void func (void) { ... }

and compiler will generate code for it as:
func:
PUSHM R1-R3; Saves the registers used in the function.
....
(R1, R2, and R3 are used in the function)
....
POPM R1-R3; Restores the registers saved at the entry.
RTE

Additionally, we can also specify some other parameters such as:
fast interrupt (in this case PC and PSW will be saved in Backup BPC and BPSW by hardware, otherwise on stack)
acc save/restore
nesting enable
use limited registers in interrupt functions and don't generate instruction for saving/restoring R6-R13 registers.

This solves my doubt.

Chandan Kumar
  • 17
  • 1
  • 5