Interrupt context saving with Pic18 port

According to Microchip ducumentation, while using interrupts, the compiler (MCC18 v3.0 and higher), automatically saves the resources that are modified within the ISR. But if a function is called from the ISR, the compiler does not know what is being modified in the function, so it plays conservatively and saves all of the compiler managed resources, including 11 registers, temp_data and MATH_DATA sections. This context saving extends the interrupted task’s stack size very much.
It is possible to exclude some registers from saving by using the “nosave” clause.
So my question is, what are registers that should be saved while calling FreeRTOS safe API funtion such as vTaskNotifyGiveFromISR or xQueueSendFromISR from ISRs?

I’m using FreeRTOS on PIC18F45k22 MCU whith MCC18 v3.7 compiler.

Thanks in advance.

We are not familiar with how the MCC18 compiler users registers, or how the register use would change across compiler versions or optimisation levels. I would recommend studying the compiler manual for information on how it uses registers, and if that does not provide the information, asking Microchip.

I do not think it is possible to tell which registers will be used without looking at the code. The compiler/optimizer will change which registers are used based on a million things, that is precisely why the safest thing is to save them all.

I believe the only way that you can ensure that specific registers are used is to write the code in assembly…

The XC8 compiler which is the latest from Microchip does a much better job at managing these registers, I would recommend you try that out, although you may have to make some changes to port your code. There is support available from Microchip to do that porting including a porting guide.