Weird code

art at ACC.ARPA art at ACC.ARPA
Thu Oct 24 16:36:35 AEST 1985


>>Ok you wizards out there, why does this program do what it does?
>>Here are a couple of hints:
>>	1) It only works on Vaxes
>>	2) The same idea is used to initialize the UNIBUS adapters
>>main()
>>{
>>        register int x, y;
>>        int i;
>>        int func();
>>
>>        fix((int *)func);
>>        x = 1; y = 5;
>>        for (i = 1; i <= 10; i++) {
>>                func(1,5);
>>                printf("x = %d, y = %d\n",x,y);
>>        }
>>}
>> ......

> ....
>This is why the code does what it does on the VAX.  I don't 
>know why they do this to initialize unibus adapters. (except maybe
>to minimize function call overhead by reducing the registers saved &
>restored at each call.)

This is done by autoconfigure when calling the probe() routines in
device drivers.  The probe routine is supposed to make the device
cause an interrupt.  An interrupt catcher figures out what vector
and priority level the interrupt used and places these in r10 and
r11.  When the interrupt catcher exits, the probe routine sees the
local variables cvec and br (which "just happen" to be in r10 and r11)
magically change.  The purpose of the entry mask "fix" is to prevent
the values in r10 and r11 from being destroyed when probe returns
to autoconfigure.  Autoconfigure has also defined cvec and br to
be local variables in r10 and r11 so these end up reflecting what
probe got.

I've always felt that this is a real kludge in 4.2 that is very
machine and even compiler dependent.  I wonder why globals were
not defined for this purpose.  Oh well, this is only one of my
irritations with 4.2's driver environment.

				"Art Berggreen"<Art at ACC.ARPA>

------



More information about the Comp.unix.wizards mailing list