Calling functions by address
    Chris Torek 
    chris at mimsy.UUCP
       
    Sat Sep 10 14:54:17 AEST 1988
    
    
  
In article <707 at starfish.Convergent.COM> cdold at starfish.Convergent.COM
(Clarence Dold) writes:
>... For QuickC, running on a PC, jumps to a ROM based routine (actually the 
>reset jump for an 8088 CPU chip)...
>
>main ()
>{
>  void (far *bye) ();
>  int far *pt;
>
>  pt = ((int far *) (0x0000472L);	[missing ) somewhere here]
>  *pt = 0x1234;                    /* for warm boot */
>  /*  *pt = 0x0000;  */           /* for cold boot */
>
>  bye = (void far *) 0x0ffff0000L;
>  (*bye) ();
>}
Incidentally, this program can be `simplified' (and from dumb-but-fast
compilers, the resulting code probably will be noticeably shorter) to
	main()
	{
		*(int far *)0x472L = 0x1234;	/* warm boot */
		/*                 = 0		   cold boot */
		(*(void (far *)())0xffff0000L)();
	}
The addresses can (and probably should) be prettied up with `#define's,
at least for anything even slightly more substantial than this example.
(I confess to being somewhat surprised at the difference between warm
and cold boots; more often, a warm boot is done by jumping to some other
address than the ROM restart address.  Something like
		#define COLDBOOT ((void (*)())0xfc000000)
		#define WARMBOOT ((void (*)())0xfc000004)
		(*(cold ? COLDBOOT : WARMBOOT))();
or if you prefer the readable version :-) ,
		if (cold) (*COLDBOOT)(); else (*WARMBOOT)();
)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris
    
    
More information about the Comp.std.c
mailing list