| Q D E V _ H L P _ D F U N C ( )
| | | | | SOURCE: qdev_macros.txt 1.16 (12/09/2014) English
AMIGA - PUBLIC
----------------------------------------------------------------------------
NAME
QDEV_HLP_DFUNC() - Creates driver function for actual
function.
SYNOPSIS
QDEV_HLP_DFUNC(r, at, dn, fn);
QDEV_HLP_DFUNC(<registers>, <type>, <driver>, <func>);
FUNCTION
This macro makes it possible to generate a wrapper func
that saves and restores particular registers so that it
is safe to use high level code in restricted code. This
macro defines the driver as global!
INPUTS
r - Register names in m68k assembly notation that are
ought to be saved and then restored. Regs can be
grouped in ranges, passed alone and/or separated
by slashes. For instance: d1-d4/d7/a1-a3/a6 .
at - Return type of the driver function. This gives a
hint to compiler on how to treat driver function
in your code.
dn - Driver function symbol.
fn - Actual function symbol. Code that will be called
by the driver.
RETURNS
No output.
BASES
None.
NOTES
A group of QDEV_DFREGS_#? contains predefined registers
for most problematic/used functions.
SEE ALSO
EXAMPLE
/*
* This routine is to utilise two registers, d0 and d1.
* Output = d0, input = d1. Compiler will save them but
* if you attempt direct assmebly pokes on other regs
* then after it returns your program may fail.
*/
LONG myroutine(REGARG(LONG in, d1))
{
/*
* This is in no way an example on how to code! It is
* a bad karma! Unfortunately some AmigaOS routines
* are coded in a similar way... But lets go back to
* the point. OK the d2 is now trashed and it was not
* saved.
*/
asm("\n\t move.l #0x0008,d2"
"\n\t rol.l #1,d2 "
"\n\t and.l d1,d2 ");
return in;
}
/*
* There is an easy way to fix this problem. We need to
* introduce the driver for this routine by taking out
* registers it uses. Registers a5(frame) and a7(stack)
* must always be discarded.
*/
QDEV_HLP_DFUNC
(
d2-d7/a0-a4/a6,
LONG, drv_myroutine,
myroutine
);
/*
* Use preprocessor to redefine symbol so that there is
* no need to edit whole code. Please keep in mind that
* the driver function defines return type only so be
* careful about arguments afterwards!
*/
#define myroutine drv_myroutine
int main(void)
{
printf("value = %ld\n", myroutine(64));
return 0;
}
BUGS
None known.
----------------------------------------------------------------------------
| |
| |