Google
 

Trailing-Edge - PDP-10 Archives - SRI_NIC_PERM_FS_1_19910112 - c/misc/c-port.txt
There are no other files named c-port.txt in the archive.
This file is a collection of messages/files that describe ways in which
other people have addressed the problems of writing portable C code.
Mostly these consist of various kinds of macro definitions.
 3-Jul-85 10:27:37-PDT,2878;000000000005
Return-Path: <WANCHO@SIMTEL20.ARPA>
Received: from SIMTEL20.ARPA by SRI-NIC.ARPA with TCP; Wed 3 Jul 85 10:27:28-PDT
Date: Wed, 3 Jul 1985  11:27 MDT
Message-ID: <WANCHO.12124088563.BABYL@SIMTEL20.ARPA>
From: "Frank J. Wancho" <WANCHO@SIMTEL20.ARPA>
To:   KLH@NIC
cc:   WANCHO@SIMTEL20.ARPA
Subject: cpu.h?

Ken,

One of the header files used on our C/70s (see below) may be of
interest to you to include as part of the KCC collection.  I'd also be
interested in what it would look like for the TOPS20 case...

I can get you sitedefs.h if you'd like to see that also.

--Frank
--------------------
/*
 * Machine-dependent parameters
 *
 * Parameters which are capable of changing between
 * sites using the same CPU should go in sitedefs.h
 * in this directory. This file is only for parameters which
 * cannot change unless the CPU does.
 *
 * As with sitedefs.h, the point of this file is to avoid the
 * need to change a program when it is shipped to a new site.
 * To this end, it avoids defining VAX, PDP11-70, etc.
 * since a program which uses such defines must be changed
 * when it is brought to a site the author did not have in
 * mind. Instead, any parameters added to this file should
 * directly answer the question the programmer had in mind:
 * e.g., if you need to know how many bits are in a word,
 * the answer is not (say) VAX, it is 32.
 *
 * To simplify the maintenance of this file, it does use
 * some names internally (as does sitedefs.h): VAX, PDP11, C70,
 * etc. These are #undeffed at the end of the file.
 */
/*
 * modified 12 June 81 for bbn-noc; bbn:yba.
 * and again 31 July 81; bbn:yba.
 * modified 26 oct 81 to add REGCACHE (C70 only) bbn:dan
 * modified 10 nov 81 to move NRMI to sitedefs.h bbn:dan
 */

/* Next Page
*/

/* CPU defines -- for use in this file only! */

/* #define PDP11 true */
/* #define PDP11_ID true       /* Has separate I & D space */						
#define C70 true
/* #define VAX true */

/* Common characteristics */

#define WORDBYTES (sizeof(int)) /* On any machine */
#define NBPW WORDBYTES

/* Individual characteristics */

#ifdef PDP11
#define BYTESIZE 8
#define BYTEMASK 0377
#define PTRSIZE  16	/* To be used in address-space-dependent algorithms */
#define BYTESLOHI 1	/* reading bytes in order lsb, msb */
#endif PDP11

#ifdef PDP11_ID
#define IDSEP	 true	/* To be used in address-space considerations */
#endif

#ifdef C70
#define BYTESIZE 10
#define BYTEMASK 01777
#define PTRSIZE  20
#define BYTESHILO 1	/* read bytes in order	msb, lsb */
#define REGCACHE 1      /* There exists a cache of registers */
#endif

#ifdef VAX
#define BYTESIZE 8
#define BYTEMASK 0377
#define PTRSIZE  32
#define BYTESLOHI 1	/* reading bytes in order lsb, msb */
#endif VAX

/* Undefs */

#undef PDP11
#undef VAX
#undef C70
#undef PDP11_ID
From: lmc@denelcor.UUCP (Lyle McElhaney)
Subject: Re: Re(cap): Which Unix?
Date: 29 Apr 85 04:10:38 GMT
To:       unix-wizards@brl-tgr.arpa

> What I'm proposing is for ALL UN*X systems to have a single
> (additional) include file: /usr/include/unix.h, which would
> contain something like:
> 
>    #define V6		0
>    #define PWB		1
>    #define V7		2
>    #define SYS3		3
>    #define 32V		4
>    #define BSD2_8	5
>    #define BSD4_1	6
>    #define SYS5		7
>    #define BSD2_9	8
>    #define BSD4_2	9
>    #define ULTRIX	10
>    #define P1003	11	/* /usr/group standard	*/
>     ...
> 
>    #define UNIX		BSD4_2

It would be nice if all Unicies had the same user interface, but hardware
considerations and sheer inertia guarantee that the problem will be with
us a while longer yet. Dave Yost published a piece in this forum stating
the above solution won't work, and presenting the solution he uses to make
the E (Rand, INed) editor work in different environments. Without further
ado, take it, Dave....

Subject: #defines for portable code
From: day@kovacs.UUCP (David Yost)
Date: Thu, 2-Aug-84 01:02:57 MDT

I have been developing and porting the Rand Editor to
different machines and systems for five years now.
(If you are interested in the significant recent
developments, mail or call 213-650-1089.)

#defined names that tell you the version of the
system, such as SYS5_2 or V7 are not the solution.
Among other problems, there are too many hacked
kernels out there, and many of the hacks are needed,
so you want your program to know they are there.

A large, sophisticated piece of software needs to
know things about the machine, the compiler, the
library functions, and the system calls.  My solution
to the porting issues has been to use two include
files: "c_env.h" for the machine and the compiler,
and "localenv.h" for the library and the kernel.

Most of what follows should be pretty obvious, but
the Regx stuff needs explanation.  Briefly, since the
compiler assigns registers in the order that it
encounters the declarations, if you just declare lots
of registers in case the machine has enough, you can
lose big on machines with fewer registers than the
number you declared.  Instead, I declare them Reg1,
Reg2, ... in the order of importance, and the c_env
#define's take care of the rest.

=== c_env.h
/*
 *   C Environment.
 *   Information about the machine and the compiler.
 *
 *   VAX 4.1bsd & 4.2bsd
 */

/*
 *  In the #define's that follow, define the first n to 'register'
 *  and the rest to nothing, where 'n' is the number of registers
 *  supported by your compiler.
 */
#define Reg1  register
#define Reg2  register
#define Reg3  register
#define Reg4  register
#define Reg5  register
#define Reg6  register
#define Reg7
#define Reg8
#define Reg9
#define Reg10
#define Reg11
#define Reg12

#define CHARMASK   0xFF
#define CHARNBITS  8
#define MAXCHAR	   0x7F

#define SHORTMASK  0xFFFF
#define SHORTNBITS 16
#define MAXSHORT   0x7FFF

#define LONGMASK  0xFFFFFFFF
#define LONGNBITS 32
#define MAXLONG	  0x7FFFFFFF

#define INTMASK	 0xFFFFFFFF
#define INTNBITS 32
#define MAXINT	 0x7FFFFFFF

#define BIGADDR		/* text address space > 64K */
/* fine ADDR64K		/* text and data share 64K of memory (no split I&D */

#define INT4		/* sizeof (int) == 4 */
/* fine INT2		/* sizeof (int) == 2 */

#define PTR4		/* sizeof (char *) == 4 */
/* fine PTR2		/* sizeof (char *) == 2 */

			/* unsigned types supported by the compiler: */
#define UNSCHAR		/* unsigned char  */
#define UNSSHORT	/* unsigned short */
#define UNSLONG		/* unsigned long  */

/* fine NOSIGNEDCHAR	/* there is no signed char type */

#define STRUCTASSIGN	/* Compiler does struct assignments */

#define UNIONS_IN_REGISTERS	/* compiler allows unions in registers */

/* fine void int	/* Fake the new 'void' type to an int */

/* Byte order: */
#define SHORT_10	/* pdp11, vax, 16000, 8086, 8080, ... */
#define LONG_3210	/* vax, 16000, 8086, 8080, ... */
/* fine LONG_0123	/* ibm, perkin-elmer, 68000, pyramid, ... */
/* fine LONG_1032	/* pdp11 */
=== localenv.h
/*
 *   System Environment
 *   Information about the system call interface and the C library.
 *
 *   4.2bsd - vax & pyramid so far
 */

/* fine index strchr		/* */
/* fine rindex strrchr		/* */
/* fine NOIOCTL_H		/* there is no ioctl.h */
/* fine RDNDELAY		/* read call has NDELAY capability */
#define EMPTY			/* can implement empty(fd) subroutine call */
#define LINKS			/* file system has links */
#define CANFORK			/* system has fork() */
#define VFORK			/* system has vfork() */
#define ABORT_SIG SIGILL	/* which signal does abort() use */
#define SIGARG			/* signal catch routine has sig num as arg */
#define SIG_INCL <signal.h>
#define SGTT_INCL <sgtty.h>
#define TTYNAME			/* use ttyname function */
/* define TTYN			/* use ttyn function */
#define SHORTUID		/* uid is a short, not a char (v7+) */
#define ENVIRON			/* getenv() is implemented */
#define VAX_MONITOR		/* use monitor() routine for vax */
#define SIGNALS			/* system has signals */
#define SYMLINKS		/* 4.2 symbolic links */
#define NDIR			/* 4.2 dirrectory routines */
#define SYSMKDIR		/* use mkdir(name, mode) system call */
#define SYSRMDIR		/* use rmdir(name) system call */
#define SYSFCHOWN		/* use fchown(fd, ...) system call */
#define SYSFCHMOD		/* use fchmod(fd, ...) system call */
#define CLR_SUID_ON_WRITE	/* modifying a file clrs suid and sgid bits */
#define SYSSELECT		/* system has berkeley select system call */
#define WAIT_UNION		/* include <sys/wait.h> */
#ifdef	WAIT_UNION
#define WAITARG union wait
#else	WAIT_UNION
#define WAITARG int
#endif	WAIT_UNION
/* fine MALLOC0OK		/* has NULL return arena corruption fix */
=== end

-- 
Lyle McElhaney
{hao, stcvax, brl-bmd, nbires, csu-cs} !denelcor!lmc