S12X CW4.5 function pointers

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

S12X CW4.5 function pointers

3,969 Views
gravity
Contributor I
Hi,
 
S12XDP512, CW 4.5, LARGE memory model
 
I have a function pointer defined as
 
typedef void (*function)(void);
 
I have a void pointer which is holding the function address  0x7DB089'G ( which is actually laid out in memory as B0897D.
 
When I attempt to cast it (or call it) the runtime GLOBAL_TO_LOCAL function is called. The result is
 
0x7DC289 (or  C2897D as laid out in memory). This is incorrect and crashes the code.
 
Any suggestions how I can get around this. I'm guessing that the routine assumes this is a data pointer and not a function pointer?
 
Cheers
 
 
 
Labels (1)
Tags (1)
0 Kudos
7 Replies

563 Views
gravity
Contributor I
Hi,
S12XDP512.
 
The problem was that I was passing the function pointer around using a "void*". I had made this "void*" a "void* far", so it was casting it to global addressing.
 
 
Cheers
 
M
 
 
 
0 Kudos

563 Views
CrasyCat
Specialist III

Hello

 Is the problem fixed now?
 If not, can you send me a code snippet reproducing the trouble.

CrasyCat

0 Kudos

563 Views
CrasyCat
Specialist III

Hello

Which CPU are you currently using (HCS12XDP512, ....)?

From what I can see (from HCS12X reference manual), address 0x7DB089'G is in fact equivalent to address 0xF6B089'L.

All absolute addresses you specify in ANSI C source code are considered as logical (even in large memory model).

So instead of writing

 typedef void (*function)(void);
 function func;


  func = (function) 0x7DB089; 
 
 func();

 You have to write

 typedef void (*function)(void);
 function func;


  func = (function) 0xF6B089; 
 
 func();

CrasyCat

0 Kudos

563 Views
gravity
Contributor I
I think my problem is S12X specific and is to do with translating from a Global address to a local address.
 
The global address is 0x7DB089'G but the local address becomes 0xF6C289'L 
 
 
 
 
0 Kudos

563 Views
gravity
Contributor I
I compiling using large memory model, so I thought everything is a far pointer?
0 Kudos

563 Views
Alban
Senior Contributor II
Sorry, but I can't confirm...
0 Kudos

563 Views
Alban
Senior Contributor II

Hi Gravity,

When you use external address space, you need to use FAR pointers to indicate to the debugger which space you address and avoid address to be truncated or wrong.

See Nabla's post and the code I had on the NE64 with extended bus.

If I understood well what you meant...
Alban.

0 Kudos