Keil Logo

C166: PAG and POF from Pointers


Information in this article applies to:

  • C166 Version 6, or higher

SYMPTOM

I have a function that was initially written for the Tasking Compiler. This function uses specific Tasking extensions that are not available in the ANSI standard:

void TskInit (unsigned int *stk, void (*task) (void), void far *p)  {
  *stk-- = _sof(task);
  *stk-- = _seg(task);

  *stk-- = _pof(p);
  *stk-- = _pag(p);
}

CAUSE

You may convert:

  • __sof: into an int cast operation.
  • __seg: into an int cast operation with shift.
  • __pag/pof: into a standard pointer assignment.

The function below has exactly the same effect and does not need any non ANSI extensions:

void TskInit (unsigned int *stk, void (*task) (void), void far *p)  {
  *stk-- = (unsigned int) task;
  *stk-- = (unsigned int) ((unsigned long) task >> 16);

  *((void far **) stk) = p;
  stk -= 2;
}

Even better would be to define a struct that represents the stack layout of the Task Control Block. However, this might be a bigger change in the system.

MORE INFORMATION

SEE ALSO


Last Reviewed: Thursday, February 25, 2021


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.