Jump to content

Wrong Code Restoring Context


Recommended Posts

Bug description:

The compiler generates wrong code to restore context from a bank other than zero.

 

In the code bellow, context is saved to bank 1 (RP0 set). At end of restoring code, clearing RP0 after restoring STATUS is useless and buggy for programs using vars in bank other than 0 (big ones).

 

***** THIS CODE FAIL TO RUN ********
Int1Context                      EQU	0x00000070; bytes:1
Int1BContext                     EQU	0x000000E0; bytes:3
ORG 0x00000000
GOTO	_startup
ORG 0x00000004
MOVWF Int1Context
SWAPF STATUS, W
BSF STATUS, RP0
BCF STATUS, RP1
MOVWF Int1BContext
SWAPF PCLATH, W
MOVWF Int1BContext+D'1'
SWAPF FSR, W
MOVWF Int1BContext+D'2'
BCF PCLATH,3
BCF PCLATH,4
GOTO	interrupt
*** interrupt service code omitted ***
label268437047
BSF STATUS, RP0
BCF STATUS, RP1
SWAPF Int1BContext+D'2', W
MOVWF FSR
SWAPF Int1BContext+D'1', W
MOVWF PCLATH
SWAPF Int1BContext, W
MOVWF STATUS
BCF STATUS, RP0
SWAPF Int1Context, F
SWAPF Int1Context, W
RETFIE
; } interrupt function end

 

How should work:

Save W to a var at same bank than interrupted code. This way, after restoring STATUS, there is no need to mess with bank selectors and would work for targets with no common memory area. BTW: why not reserve last memory position in every bank to save W?

 

Steps to reproduce:

Big programs with multibank vars.

 

Problem 100% reproduceable.

 

Workaround:

Check the code. On error, change wrong instruction messing with bank selectors to NOP. For PIC16F6xx with STATUS @ 0x83,

BCF STATUS, RP0 opcode = 0x1283

BCF STATUS, RP1 opcode = 0x1383

 

IDE version: 5.9.5

Compiler: BoostC

Compiler version:

BoostC Optimizing C Compiler Version 2.2.2 Beta (for PIC16 architecture)

Linker version:

BoostLink Optimizing Linker Version 2.2.2 Beta

Target device: PIC16F648A

OS: Windows-XP

Link to post
Share on other sites

LcSD53,

 

The context saving is split into two parts:

1) W reg

2) All other context saving.

 

The problem looks like its when the two context saving parts reside in different banks (this is how I reproduce the problem). The linker adds an extra instruction that messes things up in the context restoration:

label268437047
BSF STATUS, RP0
BCF STATUS, RP1
SWAPF Int1BContext+D'2', W
MOVWF FSR
SWAPF Int1BContext+D'1', W
MOVWF PCLATH
SWAPF Int1BContext, W
MOVWF STATUS
BCF STATUS, RP0; this extra instruction causes the problem
SWAPF Int1Context, F
SWAPF Int1Context, W
RETFIE
; } interrupt function end

 

BTW: why not reserve last memory position in every bank to save W?

Linker seeks out common bank memory, or memory that is ram is all banks. So this is already handled in a more efficient way.

 

This now fixed.

Please mail support@picant.com and I will send you an update to test.

 

Regards

Dave

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...