Good day
I have found an issue where the context saving entry and exit points of an ISR do not save all of the affected registers and cause subsequent exceptions. THis is an extremely disturbing problem in itself. To that end I am trying to write in assembler for the PIC32MX795F512L using the Mikro C Pro compiler, my own context savers for each interrupt that i use. At present I have selected the ICS_OFF Option at the definition of each ISR. so for example instead of saying;
void AriobusCan_Interrupt() iv IVT_EXTERNAL_2 ilevel 5 ics ICS_SOFT {
.... ISR contents....
}
I rather say;
void AriobusCan_Interrupt() iv IVT_EXTERNAL_2 ilevel 5 ics ICS_OFF {
.... ISR contents....
}
This seems to have the correct effect that when the .lst file is checked after compilation, there is no context saving of any registers. My problem comes in when I create an identical context saving for each ISR that the compiler would if I were not using the ICS_OFF option. (I basically copied and pasted the same assembler code that the compiler generates. This needs to EXCLUDE the saving of the Return address which is stored in the RA register as well as any ERET instructions since the compiler puts these in again anyway).
So when I compile using the compilers own generated context saving, the code works as expected. When I use my identical context saving and the ICS_OFF option, the code generates exceptions from the word go.
My question is simply this; The help documentation mentions the use of a pragma that should be used listed as follows:
#pragma disablecontextsaving
Does this need to be used in addition to the ICS_OFF option, because it seems to have no effect when placed at the top of the main() program below all my #include statements as shown below?
Thankyou
#include "uart2.h"
#include "modbus.h"
#include "spi3can.h"
#include "bit.h"
#include "testsnippets.h"
#pragma disablecontextsaving
PS. The original issue of the ISR not saving the correct context is basically as follows;
1) I call a routine in the main loop that passes two parameters, the compiler uses R25 and R26 to pass these parameters. The C -code of this is: unsigned int UART2_CalcCRC(const unsigned short int *MData, unsigned int Mlen)
the assembler version of this is:
;uart2.h, 216 :: ML_LC1 = UART2_CalcCRC(RS485_TX_Buffer, 6);
0x9D00B9A8 0x341A0006 ORI R26, R0, 6
0x9D00B9AC 0x3C19A000 LUI R25, hi_addr(_RS485_TX_Buffer+0)
0x9D00B9B0 0x0F4024C7 JAL _UART2_CalcCRC+0
0x9D00B9B4 0x37395362 ORI R25, R25, lo_addr(_RS485_TX_Buffer+0)
0x9D00B9B8 0xA422DCD0 SH R2, Offset(_ML_LC1+0)(GP)
I then have an ISR that runs fairly often, its context saving code from the .lst file looks like this;
_AriobusCan_Interrupt:
;spi3can.h, 4290 :: void AriobusCan_Interrupt() iv IVT_EXTERNAL_2 ilevel 5 ics ICS_OFF { //ICS_SOFT ICS_OFF
0x9D018DB4 0x27BDFFF8 ADDIU SP, SP, -8
0x9D018DB8 0xAFBF0000 SW RA, 0(SP)
;spi3can.h, 4293 :: asm ADDIU SP, SP, -40
0x9D018DBC 0x27BDFFD8 ADDIU SP, SP, -40
;spi3can.h, 4294 :: asm SW R30, 12(SP)
0x9D018DC0 0xAFBE000C SW R30, 12(SP)
;spi3can.h, 4295 :: asm MFC0 R30, 12, 2
0x9D018DC4 0x401E6002 MFC0 R30, 12, 2
;spi3can.h, 4296 :: asm SW R30, 8(SP)
0x9D018DC8 0xAFBE0008 SW R30, 8(SP)
;spi3can.h, 4297 :: asm MFC0 R30, 14, 0
0x9D018DCC 0x401E7000 MFC0 R30, 14, 0
;spi3can.h, 4298 :: asm SW R30, 4(SP)
0x9D018DD0 0xAFBE0004 SW R30, 4(SP)
;spi3can.h, 4299 :: asm MFC0 R30, 12, 0
0x9D018DD4 0x401E6000 MFC0 R30, 12, 0
;spi3can.h, 4300 :: asm SW R30, 0(SP)
0x9D018DD8 0xAFBE0000 SW R30, 0(SP)
;spi3can.h, 4301 :: asm INS R30, R0, 1, 15
0x9D018DDC 0x7C1E7844 INS R30, R0, 1, 15
;spi3can.h, 4302 :: asm ORI R30, R0, 5120
0x9D018DE0 0x341E1400 ORI R30, R0, 5120
;spi3can.h, 4303 :: asm MTC0 R30, 12, 0
0x9D018DE4 0x409E6000 MTC0 R30, 12, 0
;spi3can.h, 4304 :: asm SW R2, 16(SP)
0x9D018DE8 0xAFA20010 SW R2, 16(SP)
;spi3can.h, 4305 :: asm SW R3, 20(SP)
0x9D018DEC 0xAFA30014 SW R3, 20(SP)
;spi3can.h, 4306 :: asm SW R4, 24(SP)
0x9D018DF0 0xAFA40018 SW R4, 24(SP)
;spi3can.h, 4307 :: asm SW R5, 28(SP)
0x9D018DF4 0xAFA5001C SW R5, 28(SP)
;spi3can.h, 4308 :: asm SW R23, 32(SP)
0x9D018DF8 0xAFB70020 SW R23, 32(SP)
;spi3can.h, 4309 :: asm SW R24, 36(SP)
0x9D018DFC 0xAFB80024 SW R24, 36(SP)
Nowehere in the above code section does it mention R25 or R26, but of you carry on downwards in the natural progression of this same ISR, you will come accross the following code;
;spi3can.h, 4439 :: SPI3_CanRegisterRead(ARIOBUS, READ_REGISTER, RXB0D0, 1); // read RXB0D0
0x9D019144 0x341C0001 ORI R28, R0, 1
0x9D019148 0x341B0066 ORI R27, R0, 102
0x9D01914C 0x341A0003 ORI R26, R0, 3
0x9D019150 0x0F403C81 JAL _SPI3_CanRegisterRead+0
0x9D019154 0x34190001 ORI R25, R0, 1
NOte the disturbing re-use of registers R25 and R26 whose context has not been saved in the ISR context saving code shown above!!!!!!.
use of #pragma disablecontextsaving
mikroC, mikroBasic and mikroPascal PRO for Microchip’s 32-bit PIC MCUs
Author
Message
Re: use of #pragma disablecontextsaving
#2 Post by nealet » 12 Nov 2019 13:00
As seems to be the case these days, i answered my own question and found a solution. Please see the following post:
viewtopic.php?f=164&t=75571
viewtopic.php?f=164&t=75571
Return to “PIC32 PRO Compilers”
Jump to
- NECTO Studio
- ↳ IDE
- ↳ IDE General
- ↳ IDE Beta Testing
- ↳ IDE Wish List
- ↳ ARM AI Compilers
- ↳ mikroC AI for ARM
- ↳ mikroC AI for ARM General
- ↳ mikroC AI for ARM Beta Testing
- ↳ mikroC AI for ARM Wish List
- ↳ PIC AI compilers
- ↳ mikroC AI for PIC
- ↳ mikroC AI for PIC General
- ↳ mikroC AI for PIC Beta Testing
- ↳ mikroC AI for PIC Wish List
- ↳ PIC32 AI Compilers
- ↳ mikroC AI for PIC32
- ↳ mikroC AI for PIC32 General
- ↳ mikroC AI for PIC32 Beta Testing
- ↳ mikroC AI for PIC32 Wish List
- ↳ dsPIC AI Compilers
- ↳ mikroC AI for dsPIC
- ↳ mikroC AI for dsPIC General
- ↳ mikroC AI for dsPIC Beta Testing
- ↳ mikroC AI for dsPIC Wish List
- ↳ AVR AI Compilers
- ↳ mikroC AI for AVR
- ↳ mikroC AI for AVR General
- ↳ mikroC AI for AVR Beta Testing
- ↳ mikroC AI for AVR Wish List
- ↳ Additional Software
- ↳ Visual TFT AI
- ↳ Visual TFT AI General
- ↳ Visual TFT AI Beta Testing
- ↳ Visual TFT AI Wish List
- PRO Compilers
- ↳ PIC PRO Compilers
- ↳ PIC Compilers General
- ↳ mikroC PRO for PIC
- ↳ mikroC PRO for PIC General
- ↳ mikroC PRO for PIC Beta Testing
- ↳ mikroC PRO for PIC Wish List
- ↳ mikroBasic PRO compiler for PIC
- ↳ mikroBasic PRO for PIC General
- ↳ mikroBasic PRO for PIC Beta Testing
- ↳ mikroBasic PRO for PIC Wish List
- ↳ mikroPascal PRO for PIC
- ↳ mikroPascal PRO for PIC General
- ↳ mikroPascal PRO for PIC Beta Testing
- ↳ mikroPascal PRO for PIC Wish List
- ↳ dsPIC PRO Compilers
- ↳ dsPIC Compilers General
- ↳ mikroC PRO for dsPIC30/33 and PIC24
- ↳ mikroC PRO for dsPIC30/33 and PIC24 General
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 General
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 General
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Wish List
- ↳ PIC32 PRO Compilers
- ↳ PIC32 Compilers General
- ↳ mikroC PRO for PIC32
- ↳ mikroC PRO for PIC32 General
- ↳ mikroC PRO for PIC32 Beta Testing
- ↳ mikroC PRO for PIC32 Wish List
- ↳ mikroBasic PRO for PIC32
- ↳ mikroBasic PRO for PIC32 General
- ↳ mikroBasic PRO for PIC32 Beta Testing
- ↳ mikroBasic PRO for PIC32 Wish List
- ↳ mikroPascal PRO for PIC32
- ↳ mikroPascal PRO for PIC32 General
- ↳ mikroPascal PRO for PIC32 Beta Testing
- ↳ mikroPascal PRO for PIC32 Wish List
- ↳ AVR PRO Compilers
- ↳ AVR Compilers General
- ↳ mikroC PRO for AVR
- ↳ mikroC PRO for AVR General
- ↳ mikroC PRO for AVR Beta Testing
- ↳ mikroC PRO for AVR Wish List
- ↳ mikroBasic PRO compiler for AVR
- ↳ mikroBasic PRO for AVR General
- ↳ mikroBasic PRO for AVR Beta Testing
- ↳ mikroBasic PRO for AVR Wish List
- ↳ mikroPascal PRO for AVR
- ↳ mikroPascal PRO for AVR General
- ↳ mikroPascal PRO for AVR Beta Testing
- ↳ mikroPascal PRO for AVR Wish List
- ↳ FT90x PRO Compilers
- ↳ FT90x Compilers General
- ↳ mikroC PRO for FT90x
- ↳ mikroC PRO for FT90x General
- ↳ mikroC PRO for FT90x Beta Testing
- ↳ mikroC PRO for FT90x Wish List
- ↳ mikroBasic PRO compiler for FT90x
- ↳ mikroBasic PRO for FT90x General
- ↳ mikroBasic PRO for FT90x Beta Testing
- ↳ mikroBasic PRO for FT90x Wish List
- ↳ mikroPascal PRO for FT90x
- ↳ mikroPascal PRO for FT90x General
- ↳ mikroPascal PRO for FT90x Beta Testing
- ↳ mikroPascal PRO for FT90x Wish List
- ↳ 8051 PRO Compilers
- ↳ 8051 Compilers General
- ↳ mikroC PRO for 8051
- ↳ mikroC PRO for 8051 General
- ↳ mikroC PRO for 8051 Beta Testing
- ↳ mikroC PRO for 8051 Wish List
- ↳ mikroBasic PRO compiler for 8051
- ↳ mikroBasic PRO for 8051 General
- ↳ mikroBasic PRO for 8051 Beta Testing
- ↳ mikroBasic PRO for 8051 Wish List
- ↳ mikroPascal PRO for 8051
- ↳ mikroPascal PRO for 8051 General
- ↳ mikroPascal PRO for 8051 Beta Testing
- ↳ mikroPascal PRO for 8051 Wish List
- ↳ ARM PRO Compilers
- ↳ ARM Compilers General
- ↳ mikroC PRO for ARM
- ↳ mikroC PRO for ARM General
- ↳ mikroC PRO for ARM Beta Testing
- ↳ mikroC PRO for ARM Wish List
- ↳ mikroBasic PRO for ARM
- ↳ mikroBasic PRO for ARM General
- ↳ mikroBasic PRO for ARM Beta Testing
- ↳ mikroBasic PRO for ARM Wish List
- ↳ mikroPascal PRO for ARM
- ↳ mikroPascal PRO for ARM General
- ↳ mikroPascal PRO for ARM Beta Testing
- ↳ mikroPascal PRO for ARM Wish List
- ↳ Older versions of Compilers
- ↳ Older versions of mikroC Compilers
- ↳ mikroC for PIC
- ↳ mikroC General
- ↳ mikroC Beta Testing
- ↳ mikroC Wish List
- ↳ mikroC for dsPIC30/33 and PIC24
- ↳ mikroC for dsPIC30/33 and PIC24 General
- ↳ mikroC for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC for dsPIC30/33 and PIC24 Wish List
- ↳ RSC-4x mikroC
- ↳ RSC-4x mikroC General
- ↳ RSC-4x mikroC Wish List
- ↳ mikroC Beta testing
- ↳ Older versions of mikroBasic Compilers
- ↳ mikroBasic compiler for PIC
- ↳ mikroBasic General
- ↳ mikroBasic Beta Testing
- ↳ mikroBasic Wish List
- ↳ mikroBasic compiler for dsPIC30/33 and PIC24
- ↳ mikroBasic for dsPIC30/33 and PIC24 General
- ↳ mikroBasic for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroBasic compiler for AVR
- ↳ mikroBasic for AVR General
- ↳ mikroBasic for AVR Wish List
- ↳ mikroBasic Beta testing
- ↳ Older versions of mikroPascal Compilers
- ↳ mikroPascal compiler for PIC
- ↳ mikroPascal FAQ
- ↳ mikroPascal General
- ↳ mikroPascal Beta Testing
- ↳ mikroPascal Wish List
- ↳ mikroPascal Bug List
- ↳ mikroPascal compiler for dsPIC30/33 and PIC24
- ↳ mikroPascal for dsPIC30/33 and PIC24 General
- ↳ mikroPascal for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroPascal compiler for AVR
- ↳ mikroPascal for AVR General
- ↳ mikroPascal for AVR Wish List
- ↳ mikroPascal Beta testing
- ↳ Library Development Discussion
- ↳ Code Requests
- Additional Software
- ↳ Visual TFT Software
- ↳ Visual TFT General
- ↳ Visual TFT Beta Testing
- ↳ Visual TFT Wish List
- ↳ Visual GLCD Software
- ↳ Visual GLCD General
- ↳ Visual GLCD Beta Testing
- ↳ Visual GLCD Wish List
- ↳ Package Manager Software
- ↳ Package Manager General
- ↳ Package Manager Beta Testing
- ↳ Package Manager Wishlist
- ↳ GLCD Font Creator Software
- ↳ SpeakUp Software
- ↳ Timer Calculator
- ↳ CAN Calculator
- ↳ mikroBootloader
- Hardware
- ↳ Development Boards
- ↳ CODEGRIP programmer and debugger
- ↳ Mikromedia
- ↳ mikroProg™ programmer and debugger
- ↳ Development Boards Wishlist
- ↳ Review
- ↳ Click Boards release
- ↳ Hexiwear
- Website & Forums
- ↳ Libstock Discussion
- ↳ Product Announcements
- ↳ Website & Forums General Discussion
- ↳ Website & Forums Wishlist
- ↳ User Projects