Paging Issues?  Far pointers to different page not dereferencing properly?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Paging Issues?  Far pointers to different page not dereferencing properly?

918 Views
PLacerenza
Contributor II

Hello everyone,

 

I am programming a MC9S12A256 microcontroller with CodeWarrior 5.9.0.

 

I have an array of "const char *far*far const" pointers to various "const char *far const" pointer arrays holding strings.

 

Example is as follows:

const char *far*far const TextPtrs[]{ farPtr1, farPtr2 }; const char *far const farPtr1[]{ "First pointer's first string", "First pointer's second string" }; const char *far const farPtr2[]{ "Second pointer's first string", "Second pointer's second string" };

 

Around these const array declarations, I have #pragma CONST_SEG and #pragma STRING_SEG to specific pages (i.e. 0x3C8000-0x3CBFFF).  The CONST_SEG and STRING_SEG pages are different, and the strings will span over multiple pages before my project is complete.

 

So in my program, I have a function which I enter in the indices for each array, and this function should place the string in a buffer for a text display.

For arbitrary values, let's say TextPtrs address is 3C8000, farPtr1 is 3C8006, and the string in farPtr1[0]'s address is 358000.

In a local, temporary *far*far pointer (char *far*far temp2far), I place TextPtrs, then increment to the proper index.  This effectively works. (temp2far = (char *far*far)TextPtrs;  temp2far += index1;)

Then, I take a temporary *far pointer (char *far temp1far), and make it equal to the dereferenced value of the above local pointer (i.e. temp1far = *temp2far;).  THIS is where I am having my problems.  Instead of the proper value I can see in the MAP file, I get some random number, i.e. expecting 3C8006, and getting 30813b.  Generally, I believe, the value I get is within my code's default pages.

 

I've tested putting this code into the same page as the constants (#pragma CODE_SEG).  The dereferencing of the pointers to other pointers works well then, but dereferencing to the strings, which are on different pages, again, fails in a similar manner (although the random value is generally starting with 3C, pushing my suspicion that it's dereferencing to a value within the same page as the code itself).

 

I have datapage.c linked, and in the link order it is before most of the code written by myself and also before ansib.lib.

A few of my compiler variables are as follows: -CpPPAGE=RUNTIME -Cq -DHCS12 -Mb -Onf

 

So finally, my question.... what am I missing?

Labels (1)
0 Kudos
2 Replies

463 Views
kef2
Senior Contributor IV
  • In a local, temporary *far*far pointer (char *far*far temp2far), I place TextPtrs, then increment to the proper index.  This effectively works. (temp2far = (char *far*far)TextPtrs;  temp2far += index1;)
  • Then, I take a temporary *far pointer (char *far temp1far), and make it equal to the dereferenced value of the above local pointer (i.e. temp1far = *temp2far;).  THIS is where I am having my problems.

temp2far after assignment should contain address of TextPtrs array. After dereferencing it temp1far will containt address of either farPtr1 or farPtr2 array, not the address of one of strings, containted in those arrays.

I would prefer to see compileable piece of code from your side, not so many words along with not copy-pasteable and not compileable snippets. You owe me some beer for adding missing = sings in lines 02-03 and for swapping lines order :-). After some work this piece of code is working perfectly well for me:

#pragma CONST_SEG __PPAGE_SEG p3C
#pragma STRING_SEG __PPAGE_SEG p3C
const char *far const farPtr1[]={ "First pointer's first string", "First pointer's second string" };
const char *far const farPtr2[]={ "Second pointer's first string", "Second pointer's second string" }; 
const char *far *far const TextPtrs[]={ farPtr1, farPtr2 };
#pragma CONST_SEG DEFAULT
#pragma STRING_SEG DEFAULT

int index1, index2;

void main(void) {
 
const char *far*far*far temp3far;
const char *far*far temp2far;
const char *far temp1far;

temp3far = TextPtrs;
temp3far += index1;
temp2far = *temp3far; 
temp2far += index2;
temp1far = *temp2far;

After executing it, I see debugger showing proper string to the right from temp1far.

0 Kudos

463 Views
PLacerenza
Contributor II

I've change my code to be NON_BANKED and manually assign PPAGE with the page value of a *far or *far*far pointer's address, ensuring I return PPAGE to the page it was at at the start of the function, and that works.

However, I can't help but feel that the code should be able to "automatically" handle PPAGE for me.  Is what I did the proper way to handle what I needed to handle, or is there a way for PPAGE to be handled automatically by the compiler (i.e. having a *far pointer, and in dereferencing it, the compiler knows to change the page, get the value from that page, and return to the code's page)?

0 Kudos