Hi ZhangJun
Here is a summary of the problem:
I am compiling and testing the code for an MC9S12XS256 processor.
I have defined a look up table of functions which I can call.
A typical line in this table reads:
/* tU08 is an in house definition of an unsigned char or byte */
/* function prototype declarations */
typedef tU08 (* __far tFunction_far_8_ptr0)(tUSB_Max3421_Data *my_usb_hub);
/* look up table */
const tFunction_far_8_ptr0 Run_Check_Max3421 = (* BT_check_max3421);
In my application, I have a section of code which calls this routine:
/* 1. If we have not yet checked if there is a MAX3421, then do that now */
if (uUSB_Status.flags.bit.usb_checked == 0)
{
/* 1.1 try to communicate with the MAX3421 and initialise it */
uUSB_Max_Data.item.mode = USB_POWER_UP;
if (Run_Check_Max3421(&uUSB_Max_Data) == USB_SUCCESS)
{
uUSB_Status.flags.bit.usb_fitted = 1;
}
/* 1.2 Flag that we have checked the MAX3421 */
uUSB_Status.flags.bit.usb_checked = 1;
}
When I dissemble the code, I see the following. I have highlighted the offending lines in bold.
| 220: | /* 1. If we have not yet checked if there is a MAX3421, then do that now */ |
| 221: | | if (uUSB_Status.flags.bit.usb_checked == 0) |
0145 1e0000081c [5] BRSET uUSB_Status,#8,*+33 ;abs = 0166
| 222: | | { |
| 223: | | | /* 1.1 try to communicate with the MAX3421 and initialise it */ |
| 224: | | | uUSB_Max_Data.item.mode = USB_POWER_UP; |
014a c6ff [1] LDAB #255
014c 7b0000 [3] STAB uUSB_Max_Data:1
| | | |
| 227: | | | if (Run_Check_Max3421(&uUSB_Max_Data) == USB_SUCCESS) |
014f cc0000 [2] LDD #uUSB_Max_Data
0152 180b000030 [4] MOVB #PAGE(Run_Check_Max3421),/*PPAGE*/48
0157 4bfb0000 [10] CALL [Run_Check_Max3421,PCR]
015b 046104 [3] TBNE B,*+7 ;abs = 0162
| 228: | | | { |
| 229: | | | | uUSB_Status.flags.bit.usb_fitted = 1; |
015e 1c000010 [4] BSET uUSB_Status,#16
| 230: | | | } |
| 231: | | | |
| 232: | | | /* 1.2 Flag that we have checked the MAX3421 */ |
| 233: | | | uUSB_Status.flags.bit.usb_checked = 1; |
0162 1c000008 [4] BSET uUSB_Status,#8
Note the comment that the PPAGE register is at memory location 48 (0x30)
When I step through the code in the debugger, the assembler code tries to store the page number in memory location 0x30. But on the MC9S12XS processor, the PPAGE register is stored at memory location 0x15. So the PPAGE register is not set correctly. When the next line is executed (the CALL operation) the program pointer goes to the wrong page and the application crashes.
I am happy to zip up the whole of my project as I have it now for you to experiment.